package com.xingtu.testSerialport.entity;

import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ObjectUtils;
import com.xingtu.testSerialport.utils.CommonFunction;

import java.io.Serializable;

/**
 * Author:雅典娜
 * Created on 2024/4/2
 * 别总是抱怨生活不够幸运，是你欠了生活一份努力，
 * 每一个你讨厌的现在，都有一个不够努力的曾经，
 * 未来美不美，取决于你现在拼不拼。
 * Desc:
 * 后台:
 */
public class GPSData implements Serializable {
    public String dataStr;//
    public String headStr;//
    public String utctime;
    public int hour;
    public int minute;
    public double second;
    public double lat;
    public double lng;
    public String latDir;  //纬度方向 N,S
    public String lngDir;  //经度防线 E,W
    public int solutionType; //解状态

    public int satelliteNumber; //卫星数
    public int age; //差分龄期
    public double hdop; //水平经度因子
    public double altitude; //天线 海拔高度
    public String alt_units; //单位


    public int head_solutionType; //解状态
    public double heading; //航向

    public void setData(String strGGA){
        try {
            dataStr = strGGA;
            String[] arrays = strGGA.split(",", -1);
            if (arrays.length < 13) {
                return;
            }
            if (arrays[1].length() > 4) {
                utctime = (arrays[1]);
                 hour = CommonFunction.parseInt(arrays[1].substring(0, 2), 0);
                 minute = CommonFunction.parseInt(arrays[1].substring(2, 4), 0);
                 second = CommonFunction.parseDouble(arrays[1].substring(4));

            }

            if (ObjectUtils.isNotEmpty(arrays[2])) {
                //mBean_GGA.setLat(Utils.jwConvert2(Double.valueOf(arrays[2])));
                lat = (CommonFunction.parseGGAAngle(arrays[2]));
            }

            latDir = (arrays[3]);

            if (ObjectUtils.isNotEmpty(arrays[4])) {
                //mBean_GGA.setLon(Utils.jwConvert2(Double.valueOf(arrays[4])));
                lng = (CommonFunction.parseGGAAngle(arrays[4]));
            }

            lngDir =(arrays[5]);

            solutionType =(CommonFunction.parseInt(arrays[6]));
//            LogUtils.e("solutionType="+solutionType);
            satelliteNumber = (CommonFunction.parseInt(arrays[7]));
            hdop =(CommonFunction.parseDouble(arrays[8]));
            altitude = (CommonFunction.parseDouble(arrays[9]));
            alt_units = (arrays[10]);
            age = (CommonFunction.parseInt(arrays[13], 99));
        }catch (Exception e){

        }
    }

    public void setHeadData(String strHead){
        headStr = strHead;
        String[] arrays = headStr.split(",", -1);
        if (arrays.length < 16) {
            return;
        }
        // 增加解状态 [2021/8/3 18:08 HuangKun]
        String solutionStatus = arrays[9];
        int pos = solutionStatus.indexOf(";");
        if (pos != -1) {
//            head_solutionType = Integer.valueOf(solutionStatus.substring(pos + 1));
//            LogUtils.e("11111=");
        }

        LogUtils.e("arrays[12]="+arrays[12]);
        heading =  (CommonFunction.parseDouble(arrays[12]));
//        LogUtils.e("heading--"+heading);
    }
}
